package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.Course1Dao;
import com.qfedu.stussm.dao.Course2Dao;
import com.qfedu.stussm.entity.Course1;
import com.qfedu.stussm.entity.Course2;
import com.qfedu.stussm.service.intf.Course1Service;
import com.qfedu.stussm.service.intf.Course2Service;
import com.qfedu.stussm.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Course2ServiceImpl implements Course2Service {
    @Autowired
    private Course2Dao dao;
    @Override
    public int add(Course2 course2) {
        return dao.add(course2);
    }

    @Override
    public PageBeanVo selectAll(int page, int limit,String c2_name) {
        PageHelper.startPage(page, limit);
        if (c2_name != null && c2_name.length() >0){
            c2_name = "%"+c2_name+"%";
        } else {
            c2_name = null;
        }

        PageInfo<Course2> coursePageInfo = new PageInfo<>(dao.selectAll(c2_name));
        return new PageBeanVo(coursePageInfo.getTotal(), coursePageInfo.getList());
    }

    @Override
    public int update(Course2 course2) {
        return dao.update(course2);
    }

    @Override
    public int del(int c2_id) {
        return dao.del(c2_id);
    }
}
